home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / lastduel.c < prev    next >
C/C++ Source or Header  |  2000-04-08  |  10KB  |  352 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. unsigned char *lastduel_vram,*lastduel_scroll2,*lastduel_scroll1;
  13. static int scroll[16];
  14.  
  15. static struct tilemap *bg_tilemap,*fg_tilemap,*tx_tilemap;
  16. static unsigned char *gfx_base;
  17. static int gfx_bank,flipscreen;
  18.  
  19. WRITE_HANDLER( lastduel_flip_w )
  20. {
  21.     flipscreen=data&1;
  22.     coin_lockout_w(0,~data & 0x10);
  23.     coin_lockout_w(1,~data & 0x20);
  24. }
  25.  
  26. WRITE_HANDLER( lastduel_scroll_w )
  27. {
  28.     scroll[offset]=data&0xffff;  /* Scroll data */
  29. }
  30.  
  31. READ_HANDLER( lastduel_scroll1_r )
  32. {
  33.     return READ_WORD(&lastduel_scroll1[offset]);
  34. }
  35.  
  36. READ_HANDLER( lastduel_scroll2_r )
  37. {
  38.     return READ_WORD(&lastduel_scroll2[offset]);
  39. }
  40.  
  41. WRITE_HANDLER( lastduel_scroll1_w )
  42. {
  43.     COMBINE_WORD_MEM(&lastduel_scroll1[offset],data);
  44.     tilemap_mark_tile_dirty(fg_tilemap,offset/4);
  45. }
  46.  
  47. WRITE_HANDLER( lastduel_scroll2_w )
  48. {
  49.     COMBINE_WORD_MEM(&lastduel_scroll2[offset],data);
  50.     tilemap_mark_tile_dirty(bg_tilemap,offset/4);
  51. }
  52.  
  53. READ_HANDLER( lastduel_vram_r )
  54. {
  55.     return READ_WORD(&lastduel_vram[offset]);
  56. }
  57.  
  58. WRITE_HANDLER( lastduel_vram_w )
  59. {
  60.      COMBINE_WORD_MEM(&lastduel_vram[offset],data);
  61.     tilemap_mark_tile_dirty(tx_tilemap,offset/2);
  62. }
  63.  
  64. WRITE_HANDLER( madgear_scroll1_w )
  65. {
  66.     COMBINE_WORD_MEM(&lastduel_scroll1[offset],data);
  67.  
  68.     tilemap_mark_tile_dirty(fg_tilemap,(offset & 0xfff)/2);
  69. }
  70.  
  71. WRITE_HANDLER( madgear_scroll2_w )
  72. {
  73.     COMBINE_WORD_MEM(&lastduel_scroll2[offset],data);
  74.  
  75.     tilemap_mark_tile_dirty(bg_tilemap,(offset & 0xfff)/2);
  76. }
  77.  
  78. static void get_ld_tile_info(int tile_index)
  79. {
  80.     int tile=READ_WORD(&gfx_base[4*tile_index])&0x1fff;
  81.     int color=READ_WORD(&gfx_base[4*tile_index+2]);
  82.  
  83.     SET_TILE_INFO(gfx_bank,tile,color&0xf)
  84.     tile_info.flags = TILE_FLIPYX((color & 0x60)>>5);
  85.     tile_info.priority = (color&0x80)>>7;
  86. }
  87.  
  88. static void get_tile_info(int tile_index)
  89. {
  90.     int tile=READ_WORD(&gfx_base[2*tile_index])&0x1fff;
  91.     int color=READ_WORD(&gfx_base[2*tile_index+0x1000]);
  92.  
  93.     SET_TILE_INFO(gfx_bank,tile,color&0xf)
  94.     tile_info.flags = TILE_FLIPYX((color & 0x60)>>5);
  95.     tile_info.priority = (color&0x10)>>4;
  96. }
  97.  
  98. static void get_fix_info(int tile_index)
  99. {
  100.     int tile=READ_WORD(&lastduel_vram[2*tile_index]);
  101.  
  102.     SET_TILE_INFO(1,tile&0xfff,tile>>12)
  103. }
  104.  
  105. /***************************************************************************
  106.  
  107.   Start the video hardware emulation.
  108.  
  109. ***************************************************************************/
  110.  
  111. int lastduel_vh_start(void)
  112. {
  113.     bg_tilemap = tilemap_create(get_ld_tile_info,tilemap_scan_rows,TILEMAP_OPAQUE,16,16,64,64);
  114.     fg_tilemap = tilemap_create(get_ld_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT | TILEMAP_SPLIT,16,16,64,64);
  115.     tx_tilemap = tilemap_create(get_fix_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,64,32);
  116.  
  117.     if (!bg_tilemap || !fg_tilemap || !tx_tilemap)
  118.         return 1;
  119.  
  120.     fg_tilemap->transparent_pen = 0;
  121.     fg_tilemap->transmask[0] = 0x007f;
  122.     fg_tilemap->transmask[1] = 0xff10;
  123.     tx_tilemap->transparent_pen = 3;
  124.  
  125.     return 0;
  126. }
  127.  
  128. int madgear_vh_start(void)
  129. {
  130.     bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_cols,TILEMAP_OPAQUE,16,16,64,32);
  131.     fg_tilemap = tilemap_create(get_tile_info,tilemap_scan_cols,TILEMAP_TRANSPARENT | TILEMAP_SPLIT,16,16,64,32);
  132.     tx_tilemap = tilemap_create(get_fix_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,64,32);
  133.  
  134.     if (!bg_tilemap || !fg_tilemap || !tx_tilemap)
  135.         return 1;
  136.  
  137.     fg_tilemap->transparent_pen = 15;
  138.     fg_tilemap->transmask[0] = 0x80ff;
  139.     fg_tilemap->transmask[1] = 0x7f00;
  140.     tx_tilemap->transparent_pen = 3;
  141.  
  142.     return 0;
  143. }
  144.  
  145. /***************************************************************************/
  146.  
  147. void lastduel_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  148. {
  149.     int i,offs,color,code;
  150.     int colmask[16];
  151.     unsigned int *pen_usage; /* Save some struct derefs */
  152.  
  153.     /* Update tilemaps */
  154.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  155.     tilemap_set_scrollx( bg_tilemap,0, scroll[6] );
  156.     tilemap_set_scrolly( bg_tilemap,0, scroll[4] );
  157.     tilemap_set_scrollx( fg_tilemap,0, scroll[2] );
  158.     tilemap_set_scrolly( fg_tilemap,0, scroll[0] );
  159.  
  160.     gfx_bank=2;
  161.     gfx_base=lastduel_scroll2;
  162.     tilemap_update(bg_tilemap);
  163.  
  164.     gfx_bank=3;
  165.     gfx_base=lastduel_scroll1;
  166.     tilemap_update(fg_tilemap);
  167.     tilemap_update(tx_tilemap);
  168.  
  169.     /* Build the dynamic palette */
  170.     palette_init_used_colors();
  171.  
  172.     pen_usage= Machine->gfx[0]->pen_usage;
  173.     for (color = 0;color < 16;color++) colmask[color] = 0;
  174.     for(offs=0x800-8;offs>-1;offs-=8)
  175.     {
  176.         int attributes = READ_WORD(&buffered_spriteram[offs+2]);
  177.         code=READ_WORD(&buffered_spriteram[offs]) & 0xfff;
  178.         color = attributes&0xf;
  179.  
  180.         colmask[color] |= pen_usage[code];
  181.     }
  182.     for (color = 0;color < 16;color++)
  183.     {
  184.         if (colmask[color] & (1 << 0))
  185.             palette_used_colors[32*16 + 16 * color +15] = PALETTE_COLOR_TRANSPARENT;
  186.         for (i = 0;i < 15;i++)
  187.         {
  188.             if (colmask[color] & (1 << i))
  189.                 palette_used_colors[32*16 + 16 * color + i] = PALETTE_COLOR_USED;
  190.         }
  191.     }
  192.  
  193.     /* Check for complete remap and redirty if needed */
  194.     if (palette_recalc())
  195.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  196.  
  197.     /* Draw playfields */
  198.     tilemap_render(ALL_TILEMAPS);
  199.     tilemap_draw(bitmap,bg_tilemap,0);
  200.     tilemap_draw(bitmap,fg_tilemap,TILEMAP_BACK | 0);
  201.     tilemap_draw(bitmap,fg_tilemap,TILEMAP_BACK | 1);
  202.     tilemap_draw(bitmap,fg_tilemap,TILEMAP_FRONT | 0);
  203.  
  204.     /* Sprites */
  205.     for(offs=0x800-8;offs>=0;offs-=8)
  206.     {
  207.         int attributes,sy,sx,flipx,flipy;
  208.         code=READ_WORD(&buffered_spriteram[offs]);
  209.         if (!code) continue;
  210.  
  211.         attributes = READ_WORD(&buffered_spriteram[offs+2]);
  212.         sy = READ_WORD(&buffered_spriteram[offs+4]) & 0x1ff;
  213.         sx = READ_WORD(&buffered_spriteram[offs+6]) & 0x1ff;
  214.  
  215.         flipx = attributes&0x20;
  216.         flipy = attributes&0x40;
  217.         color = attributes&0xf;
  218.  
  219.         if( sy>0x100 )
  220.             sy -= 0x200;
  221.  
  222.         if (flipscreen) {
  223.             sx=384+128-16-sx;
  224.             sy=240-sy;
  225.             if (flipx) flipx=0; else flipx=1;
  226.             if (flipy) flipy=0; else flipy=1;
  227.         }
  228.  
  229.         drawgfx(bitmap,Machine->gfx[0],
  230.             code,
  231.             color,
  232.             flipx,flipy,
  233.             sx,sy,
  234.             &Machine->drv->visible_area,
  235.             TRANSPARENCY_PEN,15);
  236.     }
  237.  
  238.     tilemap_draw(bitmap,fg_tilemap,TILEMAP_FRONT | 1);
  239.     tilemap_draw(bitmap,tx_tilemap,0);
  240. }
  241.  
  242. static void ledstorm_sprites(struct osd_bitmap *bitmap, int pri)
  243. {
  244.     int offs;
  245.  
  246.     for(offs=0x800-8;offs>=0;offs-=8)
  247.     {
  248.         int attributes,sy,sx,flipx,flipy,color,code;
  249.         sy = READ_WORD(&buffered_spriteram[offs+4]) & 0x1ff;
  250.         if (sy==0x180) continue;
  251.  
  252.         code=READ_WORD(&buffered_spriteram[offs]);
  253.         attributes = READ_WORD(&buffered_spriteram[offs+2]);
  254.         sx = READ_WORD(&buffered_spriteram[offs+6]) & 0x1ff;
  255.  
  256.         flipx = attributes&0x20;
  257.         flipy = attributes&0x80; /* Different from Last Duel */
  258.         color = attributes&0xf;
  259.         if (pri==1 && (attributes&0x10)) continue;
  260.         if (pri==0 && !(attributes&0x10)) continue;
  261.  
  262.         if( sy>0x100 )
  263.             sy -= 0x200;
  264.  
  265.         if (flipscreen) {
  266.             sx=384+128-16-sx;
  267.             sy=240-sy;
  268.             if (flipx) flipx=0; else flipx=1;
  269.             if (flipy) flipy=0; else flipy=1;
  270.         }
  271.  
  272.         drawgfx(bitmap,Machine->gfx[0],
  273.             code,
  274.             color,
  275.             flipx,flipy,
  276.             sx,sy,
  277.             &Machine->drv->visible_area,
  278.             TRANSPARENCY_PEN,15);
  279.     }
  280. }
  281.  
  282. void ledstorm_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  283. {
  284.     int i,offs,color,code;
  285.     int colmask[16];
  286.     unsigned int *pen_usage; /* Save some struct derefs */
  287.  
  288.     /* Update tilemaps */
  289.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  290.     tilemap_set_scrollx( bg_tilemap,0, scroll[6] );
  291.     tilemap_set_scrolly( bg_tilemap,0, scroll[4] );
  292.     tilemap_set_scrollx( fg_tilemap,0, scroll[2] );
  293.     tilemap_set_scrolly( fg_tilemap,0, scroll[0] );
  294.  
  295.     gfx_bank=2;
  296.     gfx_base=lastduel_scroll2;
  297.     tilemap_update(bg_tilemap);
  298.  
  299.     gfx_bank=3;
  300.     gfx_base=lastduel_scroll1;
  301.     tilemap_update(fg_tilemap);
  302.     tilemap_update(tx_tilemap);
  303.  
  304.     /* Build the dynamic palette */
  305.     palette_init_used_colors();
  306.  
  307.     pen_usage= Machine->gfx[0]->pen_usage;
  308.     for (color = 0;color < 16;color++) colmask[color] = 0;
  309.     for(offs=0x800-8;offs>-1;offs-=8)
  310.     {
  311.         int attributes = READ_WORD(&buffered_spriteram[offs+2]);
  312.         code=READ_WORD(&buffered_spriteram[offs]) & 0xfff;
  313.         color = attributes&0xf;
  314.  
  315.         colmask[color] |= pen_usage[code];
  316.     }
  317.     for (color = 0;color < 16;color++)
  318.     {
  319.         if (colmask[color] & (1 << 0))
  320.             palette_used_colors[32*16 + 16 * color +15] = PALETTE_COLOR_TRANSPARENT;
  321.         for (i = 0;i < 15;i++)
  322.         {
  323.             if (colmask[color] & (1 << i))
  324.                 palette_used_colors[32*16 + 16 * color + i] = PALETTE_COLOR_USED;
  325.         }
  326.     }
  327.  
  328.     /* Check for complete remap and redirty if needed */
  329.     if (palette_recalc())
  330.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  331.  
  332.     /* Draw playfields */
  333.     tilemap_render(ALL_TILEMAPS);
  334.     tilemap_draw(bitmap,bg_tilemap,0);
  335.     tilemap_draw(bitmap,fg_tilemap,TILEMAP_BACK | 0);
  336.     tilemap_draw(bitmap,fg_tilemap,TILEMAP_BACK | 1);
  337.     tilemap_draw(bitmap,fg_tilemap,TILEMAP_FRONT | 0);
  338.     ledstorm_sprites(bitmap,0);
  339.     tilemap_draw(bitmap,fg_tilemap,TILEMAP_FRONT | 1);
  340.     ledstorm_sprites(bitmap,1);
  341.     tilemap_draw(bitmap,tx_tilemap,0);
  342. }
  343.  
  344.  
  345. void lastduel_eof_callback(void)
  346. {
  347.     /* Spriteram is always 1 frame ahead, suggesting buffering.  I can't find
  348.         a register to control this so I assume it happens automatically
  349.         every frame at the end of vblank */
  350.     buffer_spriteram_w(0,0);
  351. }
  352.